home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / IP.H < prev    next >
Text File  |  1993-08-09  |  7KB  |  208 lines

  1. #ifndef    _IP_H
  2. #define    _IP_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef    _IFACE_H
  13. #include "iface.h"
  14. #endif
  15.  
  16. #ifndef    _INTERNET_H
  17. #include "internet.h"
  18. #endif
  19.  
  20. #ifndef    _TIMER_H
  21. #include "timer.h"
  22. #endif
  23.  
  24. #define    TLB    30    /* Default reassembly timeout, sec */
  25. #define    IPVERSION    4
  26. #define    IP_MAXOPT    40    /* Largest option field, bytes */
  27.  
  28. extern int32 Ip_addr;    /* Our IP address for ICMP and source routing */
  29.  
  30. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  31. extern struct mib_entry Ip_mib[];
  32. #define    ipForwarding        Ip_mib[1].value.integer
  33. #define    ipDefaultTTL        Ip_mib[2].value.integer
  34. #define    ipInReceives        Ip_mib[3].value.integer
  35. #define    ipInHdrErrors        Ip_mib[4].value.integer
  36. #define    ipInAddrErrors        Ip_mib[5].value.integer
  37. #define    ipForwDatagrams        Ip_mib[6].value.integer
  38. #define    ipInUnknownProtos    Ip_mib[7].value.integer
  39. #define    ipInDiscards        Ip_mib[8].value.integer
  40. #define    ipInDelivers        Ip_mib[9].value.integer
  41. #define    ipOutRequests        Ip_mib[10].value.integer
  42. #define    ipOutDiscards        Ip_mib[11].value.integer
  43. #define    ipOutNoRoutes        Ip_mib[12].value.integer
  44. #define    ipReasmTimeout        Ip_mib[13].value.integer
  45. #define    ipReasmReqds        Ip_mib[14].value.integer
  46. #define    ipReasmOKs        Ip_mib[15].value.integer
  47. #define    ipReasmFails        Ip_mib[16].value.integer
  48. #define    ipFragOKs        Ip_mib[17].value.integer
  49. #define    ipFragFails        Ip_mib[18].value.integer
  50. #define    ipFragCreates        Ip_mib[19].value.integer
  51.  
  52. #define    NUMIPMIB    19
  53.  
  54. /* IP header, INTERNAL representation */
  55. struct ip {
  56.     char version;        /* IP version number */
  57.     char tos;        /* Type of service */
  58.     int16 length;        /* Total length */
  59.     int16 id;        /* Identification */
  60.     int16 offset;        /* Fragment offset in bytes */
  61.     struct {
  62.         char congest;    /* Congestion experienced bit (exp) */
  63.         char df;    /* Don't fragment flag */
  64.         char mf;    /* More Fragments flag */
  65.     } flags;
  66.  
  67.     char ttl;        /* Time to live */
  68.     char protocol;        /* Protocol */
  69.     int16 checksum;        /* Header checksum */
  70.     int32 source;        /* Source address */
  71.     int32 dest;        /* Destination address */
  72.     char options[IP_MAXOPT];/* Options field */
  73.     int optlen;        /* Length of options field, bytes */
  74. };
  75. #define    NULLIP    (struct ip *)0
  76. #define    IPLEN    20    /* Length of standard IP header */
  77.  
  78. /* Fields in option type byte */
  79. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  80. #define    OPT_CLASS    0x60    /* Option class */
  81. #define    OPT_NUMBER    0x1f    /* Option number */
  82.  
  83. /* IP option numbers */
  84. #define    IP_EOL        0    /* End of options list */
  85. #define    IP_NOOP        1    /* No Operation */
  86. #define    IP_SECURITY    2    /* Security parameters */
  87. #define    IP_LSROUTE    3    /* Loose Source Routing */
  88. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  89. #define    IP_RROUTE    7    /* Record Route */
  90. #define    IP_STREAMID    8    /* Stream ID */
  91. #define    IP_SSROUTE    9    /* Strict Source Routing */
  92.  
  93. /* Timestamp option flags */
  94. #define    TS_ONLY        0        /* Time stamps only */
  95. #define    TS_ADDRESS    1        /* Addresses + Time stamps */
  96. #define    TS_PRESPEC    3        /* Prespecified addresses only */
  97.  
  98. /* IP routing table entry */
  99. struct route {
  100.     struct route *next;     /* Linked list pointer */
  101.     int32 target;            /* Target IP address */
  102.     unsigned int bits;        /* Number of significant bits in target */
  103.     int32 gateway;            /* IP address of local gateway for this target */
  104.     int32 metric;            /* Hop count or whatever */
  105.     struct iface *iface;    /* Device interface structure */
  106.     int flags;
  107. #define    RTPRIVATE    0x1        /* Should the world be told of this route ? */
  108. #define    RTTRIG    0x2            /* Trigger is pending for this route */
  109.     struct timer timer;        /* Time until aging of this entry */
  110.     int32 uses;                /* Usage count */
  111. };
  112. #define    NULLROUTE    (struct route *)0
  113.  
  114. extern struct route *Routes;            /* Routing table */
  115. extern struct route R_default;            /* Default route entry */
  116.  
  117. /* IP routing save table entry - DB3FL */
  118. struct ip_saverecord {
  119.     int32 target;
  120.     int bits;
  121.     int32 gateway;
  122.     int niface;
  123.     int32 metric;
  124.     int flags;
  125. };
  126.  
  127. /* Reassembly descriptor */
  128. struct reasm {
  129.     struct reasm *next;    /* Linked list pointer */
  130.     struct timer timer;    /* Reassembly timeout timer */
  131.     struct frag *fraglist;    /* Head of data fragment chain */
  132.     int16 length;        /* Entire datagram length, if known */
  133.     int32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  134.     int32 dest;
  135.     int16 id;
  136.     char protocol;
  137. };
  138. #define    NULLREASM    (struct reasm *)0
  139.  
  140. /* Fragment descriptor in a reassembly list */
  141. struct frag {
  142.     struct frag *prev;    /* Previous fragment on list */
  143.     struct frag *next;    /* Next fragment */
  144.     struct mbuf *buf;    /* Actual fragment data */
  145.     int16 offset;        /* Starting offset of fragment */
  146.     int16 last;        /* Ending offset of fragment */
  147. };
  148. #define    NULLFRAG    (struct frag *)0
  149.  
  150. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  151.  
  152. /* Structure for handling raw IP user sockets */
  153. struct raw_ip {
  154.     struct raw_ip *next;    /* Linked list pointer */
  155.  
  156.     struct mbuf *rcvq;    /* receive queue */
  157.     void (*r_upcall) __ARGS((struct raw_ip *));
  158.     int protocol;        /* Protocol */
  159.     int user;        /* User linkage */
  160. };
  161. #define    NULLRIP    ((struct raw_ip *)0)
  162. extern struct raw_ip *Raw_ip;
  163.  
  164. /* Transport protocol link table */
  165. struct iplink {
  166.     char proto;
  167.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  168. };
  169. extern struct iplink Iplink[];
  170.  
  171. /* In ip.c: */
  172. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  173.     int rxbroadcast));
  174. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  175.     int rxbroadcast));
  176. int ip_send __ARGS((int32 source,int32 dest,char protocol,char tos,char ttl,
  177.     struct mbuf *bp,int16 length,int16 id,char df));
  178. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  179. void del_ip __ARGS((struct raw_ip *rrp));
  180.  
  181. /* In iproute.c: */
  182. int16 ip_mtu __ARGS((int32 addr));
  183. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  184.     int prec,int del,int tput,int rel));
  185. int ip_route __ARGS((struct iface *i_iface,struct iface *r_iface,
  186.     struct mbuf *bp,int rxbroadcast));
  187. int32 locaddr __ARGS((int32 addr));
  188. void rt_merge __ARGS((int trace));
  189. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  190.     struct iface *iface,int32 metric,int32 ttl,char private));
  191. int rt_drop __ARGS((int32 target,unsigned int bits));
  192. struct route *rt_lookup __ARGS((int32 target));
  193. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  194.  
  195. /* In iphdr.c: */
  196. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int16 len));
  197. int16 eac __ARGS((int32 sum));
  198. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  199. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  200.  
  201. /* In either lcsum.c or pcgen.asm: */
  202. int16 lcsum __ARGS((int16 *wp,int16 len));
  203.  
  204. /* In config.c: */
  205. void rt_timeout __ARGS((void *s));
  206.  
  207. #endif /* _IP_H */
  208.